package com.meituan.controller;


import com.meituan.pojo.req.RolePermissionReq;
import com.meituan.pojo.req.RoleReq;
import com.meituan.pojo.resp.BaseResp;
import com.meituan.service.RoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    RoleService roleService;

//    @RequiresPermissions(value ={"role_findAll"})
    @PostMapping("/findAll")
    public BaseResp findAll(){
        return roleService.findAll();
    }

//    @RequiresPermissions(value ={"role_delete"})
    @PostMapping("/deleteById")
    public BaseResp deleteById(@RequestBody Map map){
        return roleService.deleteById(Integer.parseInt(map.get("id").toString()));
    }

//    @RequiresPermissions(value ={"role_update"})
    @PostMapping("/saveOrUpdate")
    public BaseResp saveOrUpdate(@RequestBody RoleReq roleReq){
        return roleService.saveOrUpdate(roleReq);
    }

//    @RequiresPermissions(value ={"role_findAll"})
    @PostMapping("/findPermissionByRid")
    public BaseResp findPermissionByRid(@RequestBody Map map){
        System.out.println(map);
        return roleService.findPermissionByRid(Integer.parseInt(map.get("id").toString()));
    }

    @PostMapping("/updateRolePermission")
    public BaseResp updateRolePermission(@RequestBody RolePermissionReq rolePermissionReq ){
        return roleService.updateRolePermission(rolePermissionReq);
    }
}
